<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script src="/html/js/util.js"></script>
    <script>
        window.onload=function (){
            init(1);
        }
        async function init(pageNo) {
            let info = await ajaxGet("/product/findByItemAss", {pageNo: pageNo});
            let productStr = "";
            for (let i = 0; i < info.list.length; i++) {
                let obj = info.list[i];
                productStr += `<tr>
                               <th>${obj.name}</th><th>${obj.money}</th><th>${obj.status}</th>
                               <th><a onclick="update(${obj.id})">下架</a>
                               <a style="margin-left: 20px">更改价格</a></th>
                               </tr>`;
            }
            getObject("productBody").innerHTML=productStr;

            let pageStr="";
            for (let i=1;i<=info.pages;i++){
                pageStr+=`<a href="javascript:init(${i})" style="margin-left: 10px">${i}</a>`
            }
            getObject("pageDiv").innerHTML=pageStr;

        }

        async function update(id){
            let info=await ajaxGet("/product/updateOfStatus",{id:id})
            if (info=="ok"){
                init(1);
            }
        }
        async function beak(){
            location.href="/html/ass/index.html"
        }
    </script>
</head>
<body>
<div style="margin-left: 100px;margin-top: 100px">
    <table border="1" cellpadding="0">
        <thead>
        <tr>
            <th>商品名称</th>
            <th>商品价格</th>
            <th>商品状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="productBody"></tbody>
    </table><br>
    <div id="pageDiv" style="margin-top: 20px"></div>
    <input type="button" value="返回" onclick="beak()">
</div>
</body>
</html>